package com.ruoyi.web.controller.warehouseManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TransferStockOut;
import com.ruoyi.system.service.ITransferStockOutService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;


/**
 * 调拨出库 Controller
 *
 * @author ruoyi
 * @date 2025-06-01
 */
@Api(tags="调拨出库")
@RestController
@RequestMapping("/system/transferStockOut")
public class TransferStockOutController extends BaseController
{
    @Autowired
    private ITransferStockOutService transferStockOutService;

    /**
     * 通过调出仓库名称和调入仓库名称查询调拨出库列表
     */
    @ApiOperation("通过调出仓库名称和调入仓库名称查询调拨出库列表")
    @PreAuthorize("@ss.hasPermi('system:out:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String outWarehouseName,@RequestParam (required = false) String inWarehouseName)
    {
        startPage();
        List<TransferStockOut> list = transferStockOutService.selectTransferStockOutListByName(outWarehouseName,inWarehouseName);
        return getDataTable(list);
    }

    /**
     * 导出调拨出库列表
     */
    @ApiOperation("导出调拨出库列表")
    @PreAuthorize("@ss.hasPermi('system:out:export')")
    @Log(title = "调拨出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String outWarehouseName,@RequestParam (required = false) String inWarehouseName)
    {
        List<TransferStockOut> list = transferStockOutService.selectTransferStockOutListByName(outWarehouseName,inWarehouseName);
        ExcelUtil<TransferStockOut> util = new ExcelUtil<TransferStockOut>(TransferStockOut.class);
        util.exportExcel(response, list, "调拨出库数据");
    }

    /**
     *
     *
     * 通过id获取调拨出库详细信息
     */
    @ApiOperation("通过id获取调拨出库详细信息")
    @PreAuthorize("@ss.hasPermi('system:out:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(transferStockOutService.selectTransferStockOutById(id));
    }

    /**
     * 新增调拨出库
     */
    @ApiOperation("新增调拨出库")
    @PreAuthorize("@ss.hasPermi('system:out:add')")
    @Log(title = "调拨出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferStockOut transferStockOut)
    {
        return toAjax(transferStockOutService.insertTransferStockOut(transferStockOut));
    }

    /**
     * 修改调拨出库
     */
    @ApiOperation("修改调拨出库")
    @PreAuthorize("@ss.hasPermi('system:out:edit')")
    @Log(title = "调拨出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransferStockOut transferStockOut)
    {
        return toAjax(transferStockOutService.updateTransferStockOut(transferStockOut));
    }

    /**
     * 通过id批量删除调拨出库信息
     */
    @ApiOperation("通过id批量删除调拨出库信息")
    @PreAuthorize("@ss.hasPermi('system:out:remove')")
    @Log(title = "调拨出库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(transferStockOutService.deleteTransferStockOutByIds(ids));
    }
}
